/**
 * Created on 2007-05-16 16:46
 */
package game.frames;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;

/**
 * @author David Wallin
 */
public class OptionsFrame extends BasicFrame
{
	/**
	 * Serializable interface forces this to be declared
	 */
	private static final long		serialVersionUID = 309464705906117457L;
	private JLabel					m_Header;
	private JCheckBox				m_Sound;
	private JCheckBox				m_ReverseFlip;
	//private JCheckBox				m_HelpTextsOn;
	private JButton					m_Controls;
	private JButton					m_Main;
	
	/**
	 * 
	 */
	public OptionsFrame()
	{
		super(new GridBagLayout());
	}
	
	/* (non-Javadoc)
	 * @see frames.BasicFrame#initializeComponent()
	 */
	@Override
	protected void initializeComponent()
	{
		this.setBackground(Color.black);
		GridBagLayout gridBag = (GridBagLayout)this.getLayout();
		
		GridBagConstraints headerConstraints = new GridBagConstraints();
		headerConstraints.insets = new Insets(10, 0, 0, 0);
		headerConstraints.gridx = 1;
		headerConstraints.gridy = 0;
		headerConstraints.gridwidth = 1;
		headerConstraints.weightx = 0.5;
		
		GridBagConstraints soundConstraints = new GridBagConstraints();
		soundConstraints.insets = new Insets(10, 0, 0, 0);
		soundConstraints.gridx = 1;
		soundConstraints.gridy = 1;
		soundConstraints.gridwidth = 1;
		soundConstraints.weightx = 0.5;
		
		GridBagConstraints reverseConstraints = new GridBagConstraints();
		reverseConstraints.gridx = 1;
		reverseConstraints.gridy = 2;
		reverseConstraints.gridwidth = 1;
		reverseConstraints.weightx = 0.5;
		
		GridBagConstraints helpConstraints = new GridBagConstraints();
		helpConstraints.gridx = 1;
		helpConstraints.gridy = 3;
		helpConstraints.gridwidth = 1;
		helpConstraints.weightx = 0.5;
		
		GridBagConstraints controlsConstraints = new GridBagConstraints();
		controlsConstraints.gridx = 0;
		controlsConstraints.gridy = 4;
		controlsConstraints.gridwidth = 3;
		
		GridBagConstraints mainConstraints = new GridBagConstraints();
		mainConstraints.gridx = 1;
		mainConstraints.gridwidth = 1;
		mainConstraints.weightx = 0.5;
		mainConstraints.weighty = 1.0;
		
		m_Header = new JLabel("Options");
		m_Sound = new JCheckBox("Sound");
		m_ReverseFlip = new JCheckBox("Reverse flip");
		//m_HelpTextsOn = new JCheckBox("Help texts");
		m_Controls = new JButton("Change control mapping");
		m_Main = new JButton("Main screen");
		
		Font f = new Font("Times", Font.BOLD, 14);
		m_Header.setFont(f);
		m_Header.setHorizontalAlignment(JLabel.CENTER);
		m_Header.setVerticalAlignment(JLabel.CENTER);
		m_Header.setBackground(Color.black);
		m_Header.setForeground(Color.gray);
		
		m_Sound.setBackground(Color.black);
		m_Sound.setForeground(Color.white);
		m_ReverseFlip.setBackground(Color.black);
		m_ReverseFlip.setForeground(Color.white);
		//m_HelpTextsOn.setBackground(Color.black);
		//m_HelpTextsOn.setForeground(Color.white);
		m_Controls.addActionListener(this);
		m_Main.addActionListener(this);
		
		m_Sound.addActionListener(this);
		m_ReverseFlip.addActionListener(this);
		//m_HelpTextsOn.addActionListener(this);
		
		this.addComponent(m_Header, gridBag, headerConstraints);
		this.addComponent(m_Sound, gridBag, soundConstraints);
		this.addComponent(m_ReverseFlip, gridBag, reverseConstraints);
		//this.addComponent(m_HelpTextsOn, gridBag, helpConstraints);
		this.addComponent(m_Controls, gridBag, controlsConstraints);
		this.addComponent(m_Main, gridBag, mainConstraints);
		
		this.doLayout();
	}
	
	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent event)
	{
		Object source = event.getSource();
		
		if(source == m_Sound)
		{
			m_Settings.setSoundOn(m_Sound.isSelected());
		}
		
		if(source == m_ReverseFlip)
		{
			m_Settings.setReversedFlip(m_ReverseFlip.isSelected());
		}
		
		//if(source == m_HelpTextsOn)
		{
			//m_Settings.setHelpTextsOn(m_HelpTextsOn.isSelected());
		}
		
		if(source == m_Controls)
		{
			this.updateFrameSwitchListeners(Frames.CONTROLS);
		}
		
		if(source == m_Main)
		{
			this.updateFrameSwitchListeners(Frames.MAIN_MENU);
		}
	}
	
	public void setOptionsCheckers()
	{
		m_Sound.setSelected(m_Settings.getSoundOn());
		m_ReverseFlip.setSelected(m_Settings.getReversedFlip());
		//m_HelpTextsOn.setSelected(m_Settings.getHelpTextsOn());
	}
	
	public boolean getReverseFlipState()
	{
		return m_ReverseFlip.isSelected();
	}
}
